package cn.lll.vuehouse.service.impl;

import cn.lll.vuehouse.common.ResponseResult;
import cn.lll.vuehouse.common.ResponseStatus;
import cn.lll.vuehouse.dto.LogDto;
import cn.lll.vuehouse.entity.Loginfo;
import cn.lll.vuehouse.mapper.LoginfoMapper;
import cn.lll.vuehouse.service.LoginfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
* @author asus-pc
* @description 针对表【sys_loginfo】的数据库操作Service实现
* @createDate 2023-09-01 17:21:54
*/
@Service
public class LoginfoServiceImpl extends ServiceImpl<LoginfoMapper, Loginfo>
    implements LoginfoService{

    @Autowired
    LoginfoMapper loginfoMapper;

    @Override
    public ResponseResult getCurrentPageInfo(LogDto logDto) {
        ResponseResult responseResult = new ResponseResult();
        Page<Loginfo> loginfoPage = new Page<>(logDto.getCurrentPage(), logDto.getPageSize());
        QueryWrapper<Loginfo> loginfoQueryWrapper = new QueryWrapper<>();
        loginfoQueryWrapper.eq(StringUtils.isNotEmpty(logDto.getUsername()), "username", logDto.getUsername());
        loginfoMapper.selectPage(loginfoPage, loginfoQueryWrapper);
        List<Loginfo> records = loginfoPage.getRecords();
        long count = loginfoPage.getTotal();
        HashMap<String, Object> map = new HashMap<>();
        map.put("data", records);
        map.put("count", count);
        responseResult.success(ResponseStatus.SUCCESS, map);
        return responseResult;
    }
}




